<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="listQuery.perfectNumber"
        placeholder="输入用户ID"
        style="width: 200px; margin-right: 20px"
        class="filter-item"
        @keyup.enter.native="handleFilter_"
      />
      <el-button :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter_">
        查询
      </el-button>
    </div>

    <el-table :data="list" stripe style="width: 1100px" border>
      <el-table-column prop="perfect_number" label="ID" width="100" align="center" />
      <el-table-column prop="nick_name" label="昵称" width="200" align="center" />
      <el-table-column prop="channel_name" label="渠道名称" align="center" />
      <el-table-column prop="channel_code" label="推荐码" align="center" width="100" />
      <el-table-column prop="source" label="来源" align="center" />
      <el-table-column prop="total_amount" label="累计消费" align="center" />
      <el-table-column prop="last_login" label="登录时间" align="center" width="200" />
      <el-table-column prop="reg_time" label="注册日期" align="center" width="200" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.pageNo"
      :limit.sync="listQuery.pageSize"
      @pagination="handleFilter"
    />
  </div>
</template>

<script>
import {
  encryption2
} from '@/api/index'
import Cookies from 'js-cookie'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'ComplexTable',
  components: {
    Pagination
  },
  data() {
    return {
      listQuery: {
        perfectNumber: '',
        pageNo: 1,
        pageSize: 10,
        adminId: ''
      },
      total: 0,
      list: [],
      downloadLoading: false
    }
  },
  created() {
    this.handleFilter()
  },
  methods: {
    // 查询
    handleFilter_() {
      if (!this.listQuery.perfectNumber) {
        return this.$message({
          message: '搜索框不能为空',
          type: 'error'
        })
      }
      this.listQuery.pageNo = 1
      this.handleFilter()
    },
    handleFilter() {
      this.downloadLoading = true
      const arys = {
        adminId: this.listQuery.adminId ? this.listQuery.adminId : JSON.parse(Cookies.get('userinfo_Gulid')).admin_id,
        perfectNumber: this.listQuery.perfectNumber,
        pageNo: this.listQuery.pageNo,
        pageSize: this.listQuery.pageSize
      }
      const url = '/user/getUserbyNumber'
      encryption2(arys, url).then((res) => {
        if (res.data.status === 0) {
          this.list = res.data.result.list
          this.total = res.data.result.count
        } else {
          this.$message({
            message: res.data.text,
            type: 'error'
          })
        }
        this.downloadLoading = false
      })
    }
  }
}
</script>
<style scoped>
  .filter-container .filter-item {
    margin-bottom: 0;
  }

  .el-table--border {
    border-right: 1px solid #dfe6ec;
  }

  .filter-container {
    width: 1000px;
  }
</style>
